<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 14-5-8
 * Time: 下午11:40
 */
class Madvertise extends CI_Model{
    function __construct(){
        parent::__construct();
    }

    function getAdvertise($title)
    {
        $where = '1=1 ';
        if(!empty($title)){
            $where .= ' and `title` like "%'.$title.'%" ';
        }

        $query = $this->db->query("select * from `tbadvertise` where $where");

        $row = $query->result();

        return $row;
    }

    function getAdvertiseById($id)
    {
        $sql = "select * from `tbadvertise` where `id`=?";
        $query = $this->db->query($sql,array($id));
        $row = $query->row_array();
        return $row;
    }

    function addAdvertise($title,$start_time,$end_time)
    {
        $data = array(
            'title' => $title ,
            'start_time' => $start_time ,
            'end_time' => $end_time,
            'create_time'=>time()
        );

        $this->db->insert('tbadvertise', $data);
        return $this->db->insert_id();
    }

    function editAdvertise($id,$title,$start_time,$end_time)
    {
        $data = array(
            'title' => $title ,
            'start_time' => $start_time ,
            'end_time' => $end_time,
        );

        $this->db->where('id', $id);
        $this->db->update('tbadvertise', $data);
    }

    function deleteAdvertise($id)
    {

        $this->MAdvertisePic->deleteAdvertisePic($id);

        $idArray = explode(',',$id);
        $this->db->where_in('id', $idArray);
        $this->db->delete('tbadvertise');
    }

}